package com.onec.service.trade.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.onec.service.api.content.AesEntityContent;
import com.onec.service.api.enums.ProductEnum;
import com.onec.service.api.enums.StatusEnum;
import lombok.Data;
import org.hibernate.annotations.ColumnTransformer;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 提现订单实体：
 *
 * @author ONEC
 * @since 20201013
 */
@Data
@Entity
@Table(name = "t_bind_card_info")
public class BindCardInfo implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true)
    private Long id;

    @Column(name = "version", length = 8)
    private Integer version;

    /**
     * 代理商编号
     */
    @Column(name = "agent_id", length = 16)
    private Long agentId;
    /**
     * 商户编号
     */
    @Column(name = "merchant_id", length = 16)
    private Long merchantId;
    /**
     * 商户编号
     */
    @Column(name = "merchant_no", length = 32)
    private String merchantNo;
    /**
     * 通道编号
     */
    @Column(name = "channel_id", length = 16)
    private Long channelId;
    /**
     * 类型码编号
     */
    @Column(name = "business_code", length = 32)
    private String businessCode;
    /**
     * 下游订单号
     */
    @Column(name = "external_num", length = 32, unique = true)
    private String externalNum;
    /**
     * 上游订单号
     */
    @Column(name = "trade_num", length = 32, unique = true)
    private String tradeNum;

    /**
     * 平台流水号
     */
    @Column(name = "serial_num", length = 32, unique = true)
    private String serialNum;

    /**
     * 优惠信息：jsonobject
     */
    @Column(name = "product", length = 8)
    @Enumerated(EnumType.STRING)
    private ProductEnum product;
    /**
     * 优惠信息：jsonobject
     */
    @Column(name = "business_id", length = 16)
    private String businessId;

    /**
     * 创建时间
     */
    @Column(name = "create_time", length = 0)
    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date createTime;

    /**
     * 完成时间
     */
    @Column(name = "complete_time", length = 0)
    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date completeTime;


    /**
     * 交易订单状态
     */
    @Column(name = "status", length = 12)
    @Enumerated(EnumType.STRING)
    private StatusEnum status;

    /**
     * 交易卡号
     */
    @Column(name = "card_no")
    @ColumnTransformer(
            read = AesEntityContent.AES_DECRYPT_CARD_NO,
            write = AesEntityContent.AES_ENCRYPT_CARD_NO
    )
    private String cardNo;

    /**
     * 银行名称
     */
    @Column(name = "bank_name", length = 32)
    private String bankName;

    /**
     * 交易手机号
     */
    @ColumnTransformer(
            read = AesEntityContent.AES_DECRYPT_PHONE,
            write = AesEntityContent.AES_ENCRYPT_PHONE
    )
    @Column(name = "phone")
    private String phone;

    /**
     * 产品备注
     */
    @Column(name = "remarks", length = 64)
    private String remarks;


}
